const defaultState = {
    userId: "",
    org: "",
    role: "",
    Permission: {},
};

export const userActionsType = {
    changeUserId: "changeUserId",
    changeOrg: "changeOrg",
    changeRole: "changeRole",
    changePermission: "changePermission",
}

export const userActions = {
    changeUserId(action) {
        return Object.assign({type: userActionsType.changeUserId}, action);
    },
    changeOrg(action) {
        return Object.assign({type: userActionsType.changeOrg}, action);
    },
    changeRole(action) {
        return Object.assign({type: userActionsType.changeRole}, action);
    },
    changePermission(action) {
        return Object.assign({type: userActionsType.changePermission}, action);
    },
}

export default (state = defaultState, action) => {
    switch (action.type) {
        case userActionsType.changeUserId:
            return Object.assign({}, state, {
                userId: action.userId
            })
        case userActionsType.changeOrg:
            return Object.assign({}, state, {
                org: action.org
            })
        case userActionsType.changeRole:
            return Object.assign({}, state, {
                role: action.role
            })
        case userActionsType.changePermission:
            return Object.assign({}, state, {
                Permission: {
                    add: action.add,
                    edit: action.edit,
                    delete: action.delete,
                }
            })
        default:
            return state;
    }
};
